home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5814 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: inforamp.net!ts26-13
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help! I am baffled! (newbie) - problem.txt [1/1]
  5. Date: Tue, 06 Feb 96 22:38:38 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4f8kvg$ffl@sam.inforamp.net>
  8. References: <4euosb$qnj@atlas.uniserve.com>
  9. NNTP-Posting-Host: ts26-13.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4euosb$qnj@atlas.uniserve.com>, nowher@anyplace.com (Chris) wrote:
  13. >
  14. >TempPart.PartNum = new char[15];
  15. >...
  16. >TempPart.PartNum=TempStr;     
  17. >
  18.  
  19. Here's your problem.  You allocate a string in the first statement.  Thus you 
  20. have a string that is pointed to by TempPart.PartNum.  Then you set 
  21. TempPart.PartNum to TempStr.  This does not copy the string, this only changes 
  22. the pointer.  Now that first string you pointed to is lost in space and you 
  23. are running into big pointer problems when TempStr get deallocated.  To copy a 
  24. string use strcpy or a variant of it.  I might be wrong, since you included 
  25. only a portion of the code.
  26.  
  27. Agrivar
  28.